package com.chuji.crmcj.view;

import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.drawable.Drawable;
import android.util.AttributeSet;
import android.view.View;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.chuji.crmcj.R;

/**
 * Created by w.pitt on 2016/1/19.
 */
public class CustomerBar extends RelativeLayout {

    private TextView mTvTitle;
    private ImageView mTvIcon;
    private TextView mTvTime;
    private TextView mtv_kuang;

    public CustomerBar(Context context, AttributeSet attrs) {
        super(context, attrs);
        initView(context, attrs);
    }

    public CustomerBar(Context context) {

        this(context, null);
    }

    public CustomerBar(Context context, AttributeSet attrs, int defStyle) {
        this(context, attrs);
    }

    private void initView(Context context, AttributeSet attrs) {
        View child = View.inflate(getContext(), R.layout.layout_item_bar, null);
        mTvTitle = (TextView) child.findViewById(R.id.tv_title);
        mTvIcon = (ImageView) child.findViewById(R.id.tv_reception_icon);
        mTvTime = (TextView) child.findViewById(R.id.tv_time);
        mtv_kuang = (TextView) child.findViewById(R.id.tv_kuang);

        this.addView(child);

        // 读取刚刚我们定义的属性
        // 第一个参数：属性
        // 第二个参数：属性的数组
        TypedArray ta = context.obtainStyledAttributes(attrs,
                R.styleable.SettingItemView);
        String title = ta.getString(R.styleable.SettingItemView_title);
        Drawable drawable = ta.getDrawable(R.styleable.SettingItemView_itbackground);
        String time = ta.getString(R.styleable.SettingItemView_time);

        ta.recycle();
        mTvTitle.setText(title);
        mTvIcon.setImageDrawable(drawable);
        mTvTime.setText(time);
    }

    public void setTitle(String title) {
        mTvTitle.setText(title);
    }

    public void setTime(String time) {
        mTvTime.setText(time);
    }

    public void setIcon(Drawable mDrawable) {
        mTvIcon.setImageDrawable(mDrawable);
    }

    public TextView getIcon() {
        return mtv_kuang;
    }
}
